export default function api(api='user-center',action, params={},title="加载中") {
  return new Promise((resolve, reject) => {
	uni.showLoading({
		title: title
	});
    uniCloud.callFunction({
    	name: api,
    	data: {
    		action,
    		params
    	}
	}).then(({result})=>{
		if(result.code==1001||result.code== 403){
			uni.showLoading({
				title: "登陆过期，重新登陆中。。"
			})
			//#ifdef MP-WEIXIN
			uni.login({
				provider: 'weixin'
			}).then(code => {
				code = code[1].code
				this.$api('user-center', 'loginByWeixin', {
					code,
					invitation: 0
				}).then(res => {
					if (res.code === 0) {
						uni.hideLoading()
						// 如果使用2.7.15及以上版本建议存为uni_id_token
						uni.setStorageSync('uniIdToken', res.token)
						res.userInfo.sessionKey=res.sessionKey
						this.$store.commit('user/login', res.userInfo)
						uni.setStorageSync('uni_id_token_expired', res.tokenExpired)
					}
				})
			})
			// #endif
			//#ifdef H5
			this.$store.commit('user/logout',{})
			uni.navigateTo({
				url:"/pages/login/login",
				fail:(err)=>{
				console.log(err)	
				}
			})
			//#endif
		}else{
			resolve(result)
			uni.hideLoading()
		}
	})
  })
}